Deploy to shared hosting with GitHub Actions

TD Jayadeera
MS Club of SLIIT
Published in
5 min readMay 4, 2023

Upload the code to the GitHub repository and automatically Deploy to shared hosting.

What you will learn

1. Create a GitHub Repository.

2. Push your code to GitHub Repository from the local machine.

3. create GitHub actions

4. Use ftp Deploy code to edit master.yml

5. Create secrets

6. re-run all jobs

7. make some changes and push again

Now it’s time to go to the tutorial.

1. Create a GitHub Repository.

GitHub is a code hosting platform for version control and collaboration. Working with GitHub makes it easy for you and others to work from anywhere.

Let’s create a repository first

Go to GitHub and create an account if you don’t have one or you can log in to the GitHub account.

Then click on the profile icon on the top right corner of the GitHub page. And click Your Repositories.

Click the “New” button on the left side of the dashboard to start a new repository.

Here you can give a repository name, description, select private or public, and create the repository

Fill in the blanks and then click Create repository.

Excellent…..

You have created your store. Now let’s see how we can push our code from our local machine to this GitHub repository

2. Push your code to GitHub Repository

Go to the folder where your code is stored on your local machine.

Right click and open git bash and use below commands one by one.

If you followed the above steps correctly, your code has been uploaded to the GitHub repository.

Go to your GitHub repository and refresh the page. Your complete code is there!

3. create GitHub actions

Open your repository on GitHub and head over to Actions tab

Click on the set up a workflow yourself → as shown below

Delete all the contents of main.yml on the page as shown below

Replace the file with below contents (note this is for a project in PHP)

Let me now explain block by block what is going on

on:
push:
branches:
-master

This is where the GitHub action system is told when to run the workflow.( This represents the name of the branch that is being deploy)

name: 🚀 Deploy website on push

This is the name of the workflow. GitHub displays the names of your workflows on your repository’s actions page after you write it

jobs :
web-deploy:
nanp: Deploy
runs-on: ubuntu-latest

jobs — Groups together all the jobs that run in the workflow file.

web-deploy — Defines the name of the web-deploy job stored within the jobs section.

runs-on: ubuntu-latest — Configures the job to run on an Ubuntu Linux runner. This means that the job will execute on a fresh virtual machine hosted by GitHub.

- name: Sync files
uses: SæKirk1and/FTP-Dep10y-Actior04.3.4
with:
server: ftp.saüirkland.cæ
username: ${{ secrets.ftp_usernæe
passwrd: ${{ secrets.ftp_password
server-dir: ./htdocs/

This is where the files are now transferred to the shared hosting server. Get your FTP details from your shared hosting. Then go to your repo>settings>secrets then add the three secrets namely: server, username and then password. This action is courtesy of SamKirkland.

5. Create secrets

Open your repository on GitHub and head over to Settings tab.

Click the “Secrets and variables” button on the left side dashboard.

After, then click the Actions tab there and go to Actions secrets and variables page.

Click New repository secret on the top right of that page and create two new secrets. As mentioned in the master.yml file, Enter ftp username for name * , ftp password and your FTP account configuration for Secret *.

6. re-run all jobs

The previous repository secret failed because we didn’t know it and we have to do it back. Re-run all jobs process for that process.

Open your repository on GitHub and head over to Settings tab.

Click the “ Re-run all jobs” button on the left side dashboard

7. make some changes and push again

After making the changes in the code file, open git bash and use the following commands one by one.

git add --all
git comit -m "test Deploy to shared hosting with Github Actions"
git push

The first row shows the modified addition.

The second row shows the entry of a description of the change.

The last column shows the changes code for uploading the commend.

Congratulations…!

Now you make a change as we did in step 7 and after doing that action the auto deploy shared hosting will be done.

--

--